﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using SlamDunk.MES.Domain.Entities.PlanContxt;

namespace SlamDunk.MES.Repository.EntityConfigurations.PlanContext
{
    /// <summary>
    /// 作业计划实体映射配置
    /// </summary>
    public class ExecutionPlanConfig : IEntityTypeConfiguration<ExecutionPlan>
    {
        /// <summary>
        /// 配置
        /// </summary>
        public void Configure(EntityTypeBuilder<ExecutionPlan> builder)
        {
            //配置属性
            builder.HasKey(entity => entity.Id).IsClustered(false);
            builder.HasMany(entity => entity.MaterialAsks).WithOne(entity => entity.ExecutionPlan).IsRequired().OnDelete(DeleteBehavior.Cascade);

            //配置索引
            builder.HasIndex(entity => entity.AddedTime).IsUnique(false).IsClustered();
        }
    }
}
